/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "照壁主界面.h"
#include "编译信息.h"

#include <窗口/窗口.h>


static C_照壁* g照壁 = nullptr;

//bool on_照壁页面切换(C_Widget* self, const E_鼠标按钮& 按钮) {
//	return true;
//}








bool on_照壁页面切换(C_Widget* self, bool show) {
	g照壁->m_更新绘制属性 = true;
	return true;
}

static void on_照壁绘制(C_Widget* self, S_2D画布* 画布) {
	C_照壁* box = static_cast<C_照壁*>(self);

	box->m_背景绘制.m_属性 = f_vg_gen属性(画布);
	S_凸边图元 图元 = {};
	图元.属性 = f_vg_get属性指针(画布, box->m_背景绘制.m_属性);
	box->m_背景绘制.f_Draw(画布, 图元, E_笔刷类型::e_单色填充);

	//auto& 字体 = f_surface_get字体(*self->m_UIctx, "鸿雷板书简体");
	//box->m_文本绘制.f_Draw(画布, &字体, box->m_背景绘制.m_属性);
}

static void on_照壁布局(C_Widget* self, C_Widget** w, uint32 num) {
	if (!num) return;

	C_照壁* box = dynamic_cast<C_照壁*>(self);
	//vec2 主窗口大小 = _Vec2(S_框架::g_主窗口.front()->f_getSize());
	vec2 size = { 900, 380 };
	vec2 pos = (self->m_Size - size) * 0.5;

	switch (f_ui_get多页面页ID(box->m_页面)) {
		case 0: {
			//size.y -= 20;
			break;
		}
		case 1: {
			break;
		}
		case 2: {
			break;
		}
	}
	box->m_页面->f_setPos(pos);
	box->m_页面->f_setSize(size);
}

static void on_照壁变换(C_Widget* self) {
	C_照壁* box = static_cast<C_照壁*>(self);

	box->m_背景绘制.f_alloc(2);
	
	S_2D_PanelAttr 属性 = { {1.0f, 1.0f} };
	属性.m_Scale = {1,1};
	//属性.m_偏移 = box->m_页面->f_getPos();
	属性.m_Offset = {};
	属性.m_渐变数量 = 1;
	f_vg_set属性(box->m_画布, box->m_背景绘制.m_属性, 属性);
	//switch (f_ui_get多页面页ID(box->m_页面)) {
	//	case 0: {
	//		auto time = f_StringToWString(DEF_编译时间);
	//		box->m_文本绘制.f_alloc(2, 128);
	//		box->m_文本绘制.f_绘制文本({ {50, 50}, {20, 250} }, { 10,10,10,255 }, 0, time, E_对齐方式::e_纵向齐);
	//
	//		time = L"最近文件";
	//		box->m_文本绘制.f_绘制文本({ {self->m_Size.x - 50, 80}, {20, 250} }, { 10,10,10,255 }, 1, time, E_对齐方式::e_纵向齐);
	//		break;
	//	}
	//	case 1: {
	//		box->m_文本绘制.f_alloc(0, 128);
	//		break;
	//	}
	//	case 2: {
	//		box->m_文本绘制.f_alloc(0, 128);
	//		break;
	//	}
	//}
	vec2 size = box->m_页面->f_getSize();

	mat3X2 mat;
	mat.row0 = box->m_页面->f_getPos();
	//mat.row0 = {};
	mat.row1 = size;
	mat.row1.y -= 25;
	mat.row2 = { 6, 0 };
	box->m_背景绘制.f_set单色填充(0, mat, S_UI主题::uic_面板背景, S_Widget预设凸包图元::m_圆角矩形);

	mat.row0.y += size.y - 25;
	mat.row1.y = 25;
	mat.row2 = { 6, 0 };
	box->m_背景绘制.f_set单色填充(1, mat, S_UI主题::uic_面板背景 + S_RGBA8UI{32, 32, 30, 0}, S_Widget预设凸包图元::m_下圆角矩形);


}

static E_事件是否传递 on_照壁鼠标点击(C_Widget* self, const E_鼠标按钮& 按钮) {
	f_widget_top_close(f_ui_当前窗口管理());
	return E_事件是否传递::e_事件传递_终止;
}

C_照壁::C_照壁(S_UI渲染环境& ctx) : C_Widget(&ctx) {

	mf_绘制 = on_照壁绘制;
	mf_布局 = on_照壁布局;
	mf_变换 = on_照壁变换;
	mf_鼠标点击 = on_照壁鼠标点击;

	m_海报 = f_ui_创建图像框(ctx);

	//std::vector<std::wstring> ws = { L"文件", L"示例" };
	std::vector<C_Widget*> ws;
	m_页面 = f_ui_创建多页面(ctx, E_方向::e_横向, ws);
	f_ui_设置多页面头(m_页面, { 90, 20 });
	f_ui_多页面可关闭(m_页面, false);

	m_文件页面 = new C_照壁文件页面(ctx);
	C_Widget* t2 = new C_照壁示例页面(ctx);
	C_Widget* t3 = f_ui_创建组件();
	m_文件页面->m_WName = u"文件";
	t2->m_WName = u"示例";
	t3->m_WName = u"快捷键";
	f_ui_多页面添加页面(m_页面, m_文件页面);
	f_ui_多页面添加页面(m_页面, t2);
	//f_ui_多页面添加页面(m_页面, t3);

	m_文件页面->mf_打开关闭 = on_照壁页面切换;
	t2->mf_打开关闭 = on_照壁页面切换;
	//f_ui_set多页面添加事件(m_页面, on_照壁页面切换, { 20,20 });


	

	f_添加子组件(m_页面);

}

C_照壁::~C_照壁() {
	
}





void f_照壁_初始化(S_UI渲染环境& m_UIctx) {
	//g照壁 = f_ui_创建全屏画布(m_UIctx, S_框架::g_UIGM);
	g照壁 = new C_照壁(m_UIctx);

	g照壁->f_setSize({900, 380});
}

void f_照壁_销毁() {
	assert(g照壁);
	delete g照壁;
}


void f_照壁_打开() {
	g照壁->m_文件页面->f_构建最近文件组件();

	//f_widget_弹出顶层窗口(g照壁);
	f_widget_top_push(g照壁, 0);

	vec2 size = _Vec2(f_window_get焦点窗口大小());
	//vec2 pos = (size - g照壁->m_Size) * 0.5;
	//g照壁->f_setPos(pos);
	g照壁->f_setPos({});
	g照壁->f_setSize(size);
	//f_widget_单个部件裁剪(g照壁, { 0, 0, size.x, size.y }, pos);
	f_widget_单个部件裁剪(g照壁, { 0, 0, size.x, size.y }, {});
	//f_widget_单个部件裁剪(g照壁, { pos.x, pos.y, size.x, size.y }, {});

	f_随机切换画心纹理(g照壁->m_文件页面);
}

void f_照壁_关闭() {
	
}

